﻿Imports Equipment.Business

Public Class WorkOrderWrapper
#Region "Properties"

    Public _id As Integer
    Public Property ID As Integer
        Get
            Return _id
        End Get
        Set(ByVal value As Integer)
            _id = value
        End Set
    End Property

    Public _description As String
    Public Property Description As String
        Get
            Return _description
        End Get
        Set(ByVal value As String)
            _description = value
        End Set
    End Property

    Public _assetID As String
    Public Property AssetID As String
        Get
            Return _assetID
        End Get
        Set(ByVal value As String)
            _assetID = value
        End Set
    End Property

    Public _responsibleGroups As String
    Public Property ResponsibleGroups As String
        Get
            Return _responsibleGroups
        End Get
        Set(ByVal value As String)
            _responsibleGroups = value
        End Set
    End Property

    Public _status As String
    Public Property Status As String
        Get
            Return _status
        End Get
        Set(ByVal value As String)
            _status = value
        End Set
    End Property

    Public _assetType As String
    Public Property AssetType As String
        Get
            Return _assetType
        End Get
        Set(ByVal value As String)
            _assetType = value
        End Set
    End Property

    Public _dateDue As String
    Public Property DateDue As String
        Get
            Return _dateDue
        End Get
        Set(ByVal value As String)
            _dateDue = value
        End Set
    End Property

#End Region

    Public Shared Function ConvertToWrapperList(ByVal source As IEnumerable(Of Equipment.DataAccess.WorkOrder)) As List(Of WorkOrderWrapper)
        Dim wrapperList As New List(Of WorkOrderWrapper)

        For Each wo In source
            Dim w As New WorkOrderWrapper
            w.ID = wo.ID
            w.Description = wo.Description
            w.AssetID = wo.Asset.BarcodeID
            w.AssetType = wo.Asset.AssetType.Description
            w.DateDue = wo.DateDue.ToString("dd-MMM-yyyy")
            w.Status = WorkOrderStatus.GetDescriptionByType(wo.Status)
            w.ResponsibleGroups = String.Join(", ", wo.WorkOrderGroups.Select(Function(wog) wog.Group.Description))

            wrapperList.Add(w)
        Next

        Return wrapperList
    End Function
End Class
